package com.work.cos.web.controller.api.pr;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.work.cos.domain.entity.FootPrintLogEntity;
import com.work.cos.domain.entity.pr.PrProductEntity;
import com.work.cos.domain.vo.ComServiceResVo;
import com.work.cos.service.interfc.IFootPrintLogService;
import com.work.cos.service.interfc.pr.IPrProductService;

@RestController
@RequestMapping("/api/pr")
public class PrProductApiController {


	private static Logger LOGGER = LoggerFactory.getLogger(PrProductApiController.class);

	@Autowired
	private IPrProductService productService;
	@Autowired
	private IFootPrintLogService footPrintLogService;
	
	/**
	 * 推荐商品
	 * @return
     */
	@PostMapping(value = "/recommd")
	public ComServiceResVo queryRecommdList(){
		
		LOGGER.debug("query product is recommd... ");
		return ComServiceResVo.returnList(productService.getListByIsRecommd());
	}
	
	/**
	 * 人气商品
	 * @return
     */
	@PostMapping(value = "/red")
	public ComServiceResVo queryRedList(){
		
		LOGGER.debug("query product is red... ");
		return ComServiceResVo.returnEntity(productService.getListByIsRed());
	}
	
	/**
	 * 今日推荐
	 * @return
     */
	@PostMapping(value = "/today")
	public ComServiceResVo queryTodayList(){
		
		LOGGER.debug("query product is today... ");
		return ComServiceResVo.returnList(productService.getListByIsToday());
	}
	
	/**
	 * 严选特卖
	 * @param id
	 * @return
     */
	@PostMapping(value = "/select")
	public ComServiceResVo querySelectList(){
		
		LOGGER.debug("query product is select... ");
		return ComServiceResVo.returnList(productService.getListByIsSelect());
	}
	
	/**
	 * 品牌团
	 * @return
     */
	@PostMapping(value = "/brand")
	public ComServiceResVo queryBrandList(){
		
		LOGGER.debug("query product is brand... ");
		return ComServiceResVo.returnList(productService.getListByIsBrand());
	}

	/**
	 * 查询产品详情
	 * @param id
	 * @return
     */
	@PostMapping(value = "/query")
	public ComServiceResVo queryProductList(@RequestParam Long id,@RequestParam Long userId){
		LOGGER.debug("query product ... ");
		PrProductEntity entity = productService.getOne(id);
		
		if(null == entity){
			
			return ComServiceResVo.returnErrorMessage("此商品不存在!");
		}
		
		//足迹
		FootPrintLogEntity footEntity = new FootPrintLogEntity();
		footEntity.setImage(entity.getImageZoomIn());
		footEntity.setPresentPrice(entity.getPresentPrice());
		footEntity.setCostPrice(entity.getCostPrice());
		footEntity.setProductId(entity.getId());
		footEntity.setUserId(userId);
		footPrintLogService.addFootPrintLog(footEntity);
		
		return ComServiceResVo.returnEntity(entity);
	}
}
